***Study 2: IV regression
use "study2.dta" 
reg hariv_volatility_100words daylight lnWC if WC>300, r //Table3 (1)
reg hariv_volatility_5chunks daylight lnWC if WC>300, r //Table3 (2)
reg hariv_volatility_20overlap daylight lnWC if WC>300, r //Table3 (3)
ivregress 2sls hariv_volatility_100words (daylight = iv1 iv2) lnWC if WC>300 //robust
ivregress 2sls hariv_volatility_5chunks (daylight = iv1 iv2) lnWC if WC>300 //robust
ivregress 2sls hariv_volatility_20overlap (daylight = iv1 iv2) lnWC if WC>300, first //Table3 (4)(5)
estat firststage, all forcenonrobust //underidentification test - minimum eigenvalue statistic
estat overid //exogeneity test - Sargan χ2 & Basmann χ2

***Study 3: Analysis of International News
use "study3.dta" 
///calculate daylength according to Forsythe et al.(1995)
*gen day-of-year（DOY）
gen doy = doy(date_var)
*set southern hemisphere as -1
gen lat_signed = cond(north == 1, latitude, -latitude)
*define CBM function
gen theta = 0.2163108 + 2 * atan(0.9671396 * tan(0.00860 * (doy - 186)))
gen delta = asin(0.39795 * cos(theta))
gen lat_rad = lat_signed * _pi / 180
gen delta_rad = delta
gen p_rad = 0.8333 * _pi / 180
gen cos_arg = (sin(p_rad) + sin(lat_rad) * sin(delta_rad)) / (cos(lat_rad) * cos(delta_rad))
replace cos_arg = max(min(cos_arg, 1), -1)
*calculate daylength
gen daylength = 24 - (24 / _pi) * acos(cos_arg)
*regression
reghdfe emotionalexpression daylength lnWC if WC>300 , absorb( nation press year) vce(r) //Table4 (1)
reghdfe emotionalexpression daylength lnWC if WC>300 & sunvariance ==0, absorb( nation press year) vce(r) //Table4 (2)
reghdfe emotionalexpression daylength lnWC if WC>300 & sunvariance ==1, absorb( nation press year) vce(r) //Table4 (3)

***Study 4: Supplementary Analysis of Financial News
use "study4.dta" 
reghdfe emotion daylight, absorb( province press month ) vce(cluster province) //Table5 (1)
reghdfe emotion daylight if sunvariance == 0, absorb( province press month ) vce(cluster province) //Table5 (2)
reghdfe emotion daylight if sunvariance == 1, absorb( province press month ) vce(cluster province) //Table5 (3)